package com.example.video.adapter

import android.graphics.Color
import android.graphics.drawable.Drawable
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.TypeVideoEntity
import com.example.video.R

class TypeAdapter:BaseQuickAdapter<TypeVideoEntity,BaseViewHolder>(R.layout.item_type) {
    var channelId = "94349546935"//默认选中的是游戏 他的channelId
    override fun convert(holder: BaseViewHolder, item: TypeVideoEntity) {
        holder.setText(R.id.type_tv,item.typename)
        if(channelId==item.channelid){
            //此item被选中，显示选中的样式
            holder.getView<TextView>(R.id.type_tv).setTextColor(Color.RED)
            holder.getView<TextView>(R.id.type_tv).setBackgroundResource(R.drawable.bg_item_type)
        }else{
            holder.getView<TextView>(R.id.type_tv).setTextColor(Color.BLACK)
            holder.getView<TextView>(R.id.type_tv).background = null
        }
    }

    fun setId(id:String){
        channelId = id
        notifyDataSetChanged()//调用此方法，页面可刷新
    }
}